<template>
<div>
  <el-dialog width="400px" title="登录" :visible="dialogFormVisible">
    <el-form  size="mini" :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.username" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.password" auto-complete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini">取 消</el-button>
      <el-button size="mini" type="primary" @click="submitForm">确 定</el-button>
    </div>
  </el-dialog>
</div>
</template>

<script>
import {login} from "@/api/login";

export default {
  name: "loginIndex",
  data() {
    return {
      dialogFormVisible: true,
      form: {
        username: 'ls',
        password: '123',
      }
    }
  },
  methods: {
    submitForm() {
      login(this.form).then(resp => {
        if (resp.code == 200) {
          sessionStorage.setItem("token", JSON.stringify(resp.data));
          this.$router.push('/index');
        } else {
          this.$message.error('登录失败');
        }
      })
    }
  }
}
</script>

<style scoped>

</style>